package model.entity;

import java.util.Date;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name = "Sales")
public class Sales {

	private int salesId;
	private News news;
	private Date dateEnd;
	private List<SalesDetails> salesDetailses = new ArrayList<SalesDetails>(0);

	public Sales() {
	}

	public Sales(int salesId, News news, Date dateEnd) {
		this.salesId = salesId;
		this.news = news;
		this.dateEnd = dateEnd;
	}

	public Sales(int salesId, News news, Date dateEnd,
			List<SalesDetails> salesDetailses) {
		this.salesId = salesId;
		this.news = news;
		this.dateEnd = dateEnd;
		this.salesDetailses = salesDetailses;
	}

	@Id
	@GeneratedValue(generator = "Sales_ID_Gen", strategy = GenerationType.IDENTITY)
	@SequenceGenerator(name = "Sales_ID_Gen", sequenceName = "Sales_SEQ_ID")
	@Column(name = "SalesID", unique = true, nullable = false)
	public int getSalesId() {
		return this.salesId;
	}

	public void setSalesId(int salesId) {
		this.salesId = salesId;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "SalesID", unique = true, nullable = false, insertable = false, updatable = false)
	public News getNews() {
		return this.news;
	}

	public void setNews(News news) {
		this.news = news;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "DateEnd", nullable = false, length = 23)
	public Date getDateEnd() {
		return this.dateEnd;
	}

	public void setDateEnd(Date dateEnd) {
		this.dateEnd = dateEnd;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "sales")
	public List<SalesDetails> getSalesDetailses() {
		return this.salesDetailses;
	}

	public void setSalesDetailses(List<SalesDetails> salesDetailses) {
		this.salesDetailses = salesDetailses;
	}

}
